// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程：https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129


module.exports = {
	_before: function() { // 通用预处理器

	},

	/**
	 * 获取我的课程列表
	 */
	async getList(skip = 0, limit = 8) {
		const dbJQL = uniCloud.databaseForJQL({
			clientInfo: this.getClientInfo()
		});

		const userCourse = dbJQL.collection("user-course").where(`userId==$cloudEnv_uid`).field('courseId')
			.getTemp();
		const course = dbJQL.collection("course").getTemp();
		let res = await dbJQL.collection(userCourse, course).field(`arrayElemAt(courseId, 0) as course`)
			.orderBy("createTime desc").skip(skip).limit(limit).get();
		res.data = res.data.map(item => {
			return item.course;
		})
		return res;
	}
}